// detail.js
Page({
  data: {
    statusBarHeight: 0,
    navHeight: 132,
    detailInfo: {},
    type: 'hotel', // hotel, restaurant, toilet
    currentImageIndex: 0,
    images: []
  },

  onLoad(options) {
    console.log('详情页面加载', options)
    this.getSystemInfo()
    
    // 从参数中获取类型和ID
    const { type = 'hotel', id } = options
    this.setData({ type })
    
    // 根据类型和ID获取详情数据
    this.getDetailData(type, id)
  },

  // 获取系统信息
  getSystemInfo() {
    const systemInfo = wx.getSystemInfoSync()
    this.setData({
      statusBarHeight: systemInfo.statusBarHeight
    })
  },

  // 获取详情数据
  getDetailData(type, id) {
    // 模拟获取详情数据
    let detailData = {}
    
    if (type === 'hotel') {
      detailData = this.getHotelDetail(id)
    } else if (type === 'restaurant') {
      detailData = this.getRestaurantDetail(id)
    } else if (type === 'toilet') {
      detailData = this.getToiletDetail(id)
    }
    
    this.setData({
      detailInfo: detailData,
      images: detailData.images || []
    })
  },

  // 获取酒店详情数据
  getHotelDetail(id) {
    const hotelData = {
      1: {
        id: 1,
        title: "黑麋峰山景度假酒店",
        subtitle: "体验山林间的宁静时光",
        description: "坐落在黑麋峰森林公园的核心地带，酒店融合了现代舒适与自然野趣。每间客房都配备观景阳台，可以欣赏到壮丽的山景和日出日落。酒店提供多样化的户外活动，包括森林徒步、观鸟、瑜伽课程等，让您在繁忙的都市生活中找到内心的宁静。",
        location: "黑麋峰森林公园内 · 距离主峰2公里",
        detailAddress: "湖南省长沙市望城区黑麋峰森林公园景区内",
        price: 368,
        period: "晚",
        rating: 4.8,
        reviewCount: 127,
        openTime: "24小时营业",
        checkIn: "14:00",
        checkOut: "12:00",
        images: [
          "/images/民宿1.jpg",
          "/images/民宿2.jpg", 
          "/images/民宿3.jpg",
          "/images/民宿4.jpg",
          "/images/景点-1.jpg",
          "/images/景点-2.jpg"
        ],
        facilities: ["免费WiFi", "山景阳台", "温泉浴池", "免费停车", "24小时前台", "行李寄存"],
        tags: ["度假酒店", "山景房", "温泉", "亲子友好", "宠物友好"],
        contact: {
          phone: "0731-88888888",
          wechat: "heimifeng_hotel"
        },
        host: {
          name: "李经理",
          avatar: "/images/113242511646348178.jpg",
          phone: "13800138000",
          isVerified: true
        }
      },
      2: {
        id: 2,
        title: "峡谷栈道观景民宿",
        subtitle: "推窗即见峡谷美景",
        description: "这是一家精品民宿，位于峡谷栈道入口处，拥有得天独厚的地理位置。民宿设计简约现代，每个房间都有大面积的观景窗，让您在房间内就能欣赏到峡谷的壮丽景色。步行5分钟即可到达观景台，是摄影爱好者和自然爱好者的理想选择。",
        location: "峡谷栈道入口 · 步行5分钟到观景台",
        detailAddress: "湖南省长沙市望城区黑麋峰森林公园峡谷栈道入口",
        price: 298,
        period: "晚",
        rating: 4.6,
        reviewCount: 89,
        openTime: "24小时营业",
        checkIn: "15:00",
        checkOut: "11:00",
        images: [
          "/images/民宿2.jpg",
          "/images/民宿3.jpg",
          "/images/景点-2.jpg",
          "/images/景点-3.jpg",
          "/images/景点-4.jpg"
        ],
        facilities: ["观景露台", "免费停车", "24小时热水", "免费WiFi", "空调", "独立卫生间"],
        tags: ["观景民宿", "峡谷景观", "摄影基地", "情侣推荐", "安静舒适"],
        contact: {
          phone: "0731-99999999",
          wechat: "canyon_view_bnb"
        },
        host: {
          name: "王女士",
          avatar: "/images/113242511646348178.jpg",
          phone: "13900139000",
          isVerified: true
        }
      }
    }
    
    return hotelData[id] || hotelData[1]
  },

  // 获取餐厅详情数据
  getRestaurantDetail(id) {
    const restaurantData = {
      11: {
        id: 11,
        title: "黑麋峰农家菜馆",
        subtitle: "正宗湘菜·地道农家风味",
        description: "传承三代的农家菜馆，坚持使用当地新鲜食材，烹饪最地道的湘菜。招牌菜包括土鸡汤、野菜炒蛋、农家腊肉等。餐厅环境古朴典雅，可以品尝到最原汁原味的乡村美食，感受浓浓的乡土情怀。",
        location: "景区入口处 · 停车方便",
        detailAddress: "湖南省长沙市望城区黑麋峰森林公园游客服务中心旁",
        price: 68,
        period: "人均",
        rating: 4.5,
        reviewCount: 234,
        openTime: "09:00 - 21:00",
        images: [
          "/images/攻略照片1.jpg",
          "/images/攻略照片2.jpg",
          "/images/攻略照片3.jpg",
          "/images/攻略照片4.jpg",
          "/images/中餐馆.png"
        ],
        features: ["特色土鸡", "野菜时蔬", "农家腊肉", "竹筒饭", "山泉水豆腐", "野生菌汤"],
        tags: ["湘菜馆", "农家菜", "当地特色", "家庭聚餐", "经济实惠"],
        contact: {
          phone: "0731-88888888",
          wechat: "heimifeng_farm"
        },
        specialties: ["土鸡汤", "野菜炒蛋", "农家腊肉", "竹筒饭"],
        services: ["包间服务", "外卖服务", "团体用餐", "停车服务"]
      },
      12: {
        id: 12,
        title: "山顶茶餐厅", 
        subtitle: "品茶观景·悠然时光",
        description: "位于黑麋峰主峰观景台旁的精品茶餐厅，拥有270度全景视野。餐厅主营茶饮、精致茶点和轻食，选用当地优质茶叶，营造宁静优雅的品茶环境。在这里可以一边品茗一边欣赏远山近水，体验真正的慢生活节奏。",
        location: "主峰观景台旁 · 270度全景视野",
        detailAddress: "湖南省长沙市望城区黑麋峰森林公园主峰观景平台",
        price: 45,
        period: "人均",
        rating: 4.8,
        reviewCount: 156,
        openTime: "08:00 - 18:00",
        images: [
          "/images/攻略照片2.jpg",
          "/images/攻略照片3.jpg",
          "/images/攻略照片4.jpg",
          "/images/攻略照片5.jpg",
          "/images/景点-1.jpg"
        ],
        features: ["云雾茶", "精致茶点", "观景座位", "手工糕点", "现磨咖啡", "花草茶"],
        tags: ["景观茶室", "下午茶", "观景平台", "情侣约会", "文艺清新"],
        contact: {
          phone: "0731-99999999",
          wechat: "mountain_tea_house"
        },
        specialties: ["云雾绿茶", "山花蜜茶", "手工点心", "景观咖啡"],
        services: ["WiFi服务", "观景座位", "拍照服务", "茶艺表演"]
      }
    }
    
    return restaurantData[id] || restaurantData[11]
  },

  // 获取厕所详情数据
  getToiletDetail(id) {
    // 厕所详情相对简单，主要是位置和设施信息
    return {
      id: id,
      title: "游客服务中心卫生间",
      subtitle: "标准公厕·设施完善",
      location: "景区主入口游客服务中心内",
      status: "正常开放",
      features: ["母婴室", "无障碍设施", "24小时开放"],
      distance: "距离您 50米"
    }
  },

  // 导航栏返回按钮
  onNavBackTap() {
    wx.navigateBack({
      delta: 1,
      fail: () => {
        wx.reLaunch({
          url: '/pages/hotel/hotel'
        })
      }
    })
  },

  // 导航栏高度变化
  onNavHeightChange(e) {
    const { totalHeight } = e.detail
    this.setData({
      navHeight: totalHeight
    })
  },

  // 图片轮播变化
  onSwiperChange(e) {
    this.setData({
      currentImageIndex: e.detail.current
    })
  },

  // 图片预览
  onImageTap(e) {
    const { current } = e.currentTarget.dataset
    wx.previewImage({
      current: this.data.images[current],
      urls: this.data.images
    })
  },

  // 电话联系
  onCallTap() {
    const phone = this.data.detailInfo.contact?.phone || this.data.detailInfo.host?.phone
    if (phone) {
      wx.makePhoneCall({
        phoneNumber: phone,
        fail: () => {
          wx.showToast({
            title: '拨打电话失败',
            icon: 'none'
          })
        }
      })
    }
  },

  // 微信联系
  onWechatTap() {
    const wechat = this.data.detailInfo.contact?.wechat
    if (wechat) {
      wx.setClipboardData({
        data: wechat,
        success: () => {
          wx.showToast({
            title: '微信号已复制',
            icon: 'success'
          })
        }
      })
    }
  },

  // 导航功能
  onNavigateTap() {
    const { title, detailAddress } = this.data.detailInfo
    wx.showModal({
      title: '选择导航方式',
      content: `将为您导航到：${title}`,
      confirmText: '确定导航',
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '正在启动导航...',
            icon: 'loading'
          })
          // 这里可以接入实际的地图导航API
        }
      }
    })
  },

  // 预订功能
  onBookTap() {
    const { type, detailInfo } = this.data
    const action = type === 'hotel' ? '预订房间' : '预订座位'
    
    wx.showModal({
      title: '预订确认',
      content: `您确定要${action}"${detailInfo.title}"吗？`,
      confirmText: '确认预订',
      confirmColor: '#ff7e00',
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '预订成功',
            icon: 'success'
          })
        }
      }
    })
  }
})
